import {UserActions} from './user';

const initialState = {};

export const ConversationActions = {
  UPDATE_CONVERSATION: 'update_conversation',
  UPDATE_CONVERSATION_MESSAGE: 'update_conversation_message',
  RESET_CONVERSATION: 'reset_conversation',
};

export function updateConversation(payload) {
  return {
    type: ConversationActions.UPDATE_CONVERSATION,
    payload,
  };
}

export function updateConversationMessage(payload) {
  return {
    type: ConversationActions.UPDATE_CONVERSATION_MESSAGE,
    payload,
  };
}

export function resetConversation() {
  return {
    type: ConversationActions.RESET_CONVERSATION,
  };
}

export default function conversation(state = initialState, action) {
  switch (action.type) {
    case ConversationActions.UPDATE_CONVERSATION:
      return {...state, ...action.payload};
    case ConversationActions.UPDATE_CONVERSATION_MESSAGE:
      state.messages.push(action.payload);
      return {...state};
    case ConversationActions.RESET_CONVERSATION:
      return {};
    case UserActions.USER_SIGN_OUT:
      return {};
    default:
      return state;
  }
}
